// pages/myRecruit/myRecruit.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: '',
    currentPage: 1,
    loadMoreTxt: '正在加载数据。。。',
    loadMore: false,
    hasData: true,
    actiItem: [],
    userInfo:'',
    loadSuccess:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var title = '全职';
    if (options.page == '2') {//全职查看更多
      title = '兼职';
    }else if(options.page=='3'){
      
    }
    wx.setNavigationBarTitle({
      title: title
    })
    this.setData({
      userInfo: JSON.parse(wx.getStorageSync('userInfo')),
      page: options.page
    })
    
  },
  getPositionInfo: function (flag) {
    var that = this;
    var param = {
      userId: this.data.userInfo.id,
      currentPage: this.data.currentPage,
      pageNumber: 10,//this.data.seachValue
    };
    if (this.data.page == '1' || this.data.page == '2'){
      param.property = this.data.page == '1' ? '全职' :'兼职';
    }
    wx.request({
      url: app.globalData.httpApiCar + 'recruitPositionInfo/page', //仅为示例，并非真实的接口地址
      data: param,
      success: function (res) {
        wx.hideLoading();
        that.setData({
          loadSuccess: true
        })
        if (res.data.success) {
          if (res.data.data.pp.length < 10) {
            that.setData({
              hasData: false
            })
          } else {
            that.setData({
              hasData: true
            })
          }
          if (flag) {
            wx.hideNavigationBarLoading() //完成停止加载
            wx.stopPullDownRefresh() //停止下拉刷新
            that.setData({
              actiItem: []
            });
          } else {
            that.setData({
              loadMore: false
            });
          }
          that.data.actiItem = that.data.actiItem.concat(res.data.data.pp);
          that.setData({
            actiItem: that.data.actiItem
          })
        }
      }
    })
  },
  showDetail: function (e) {
    wx.setStorage({
      key: 'infoItem',
      data: e.currentTarget.dataset.item,
    })
    if (this.data.page == '1') {//全职
      wx.navigateTo({
        url: '/pages/pulishFullJob/pulishFullJob?isEdit=true'
      })
    } else {//兼职
      wx.navigateTo({
        url: '/pages/pulishPartJob/pulishPartJob?isEdit=true'
      })
    } 
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      loadSuccess: false
    })
    wx.showLoading();
    this.getPositionInfo(true); 
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.showNavigationBarLoading(); //在标题栏中显示加载
    this.setData({
      currentPage: 1
    })
    this.getPositionInfo(true);
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (that.data.hasData) {
      this.setData({
        loadMoreTxt: '正在加载数据。。。',
        loadMore: true,
        currentPage:this.data.currentPage + 1 
      });
      this.getPositionInfo();
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})